package com.binarysoft.service.user;

import com.binarysoft.service.user.UserInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface UserInfoMapper {
    @Delete({
        "delete from user_info",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(long id);

    @Insert({
        "insert into user_info (id, name, ",
        "surname, description, ",
        "email, phone_num, ",
        "locale, active, ",
        "deleted, login_id, ",
        "login_pass, creation_time, ",
        "last_updated_time, last_login_time)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{surname,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{phoneNum,jdbcType=VARCHAR}, ",
        "#{locale,jdbcType=VARCHAR}, #{active,jdbcType=INTEGER}, ",
        "#{deleted,jdbcType=INTEGER}, #{loginId,jdbcType=VARCHAR}, ",
        "#{loginPass,jdbcType=VARCHAR}, #{creationTime,jdbcType=DATE}, ",
        "#{lastUpdatedTime,jdbcType=DATE}, #{lastLoginTime,jdbcType=DATE})"
    })
    int insert(UserInfo record);

    @InsertProvider(type=UserInfoSqlProvider.class, method="insertSelective")
    int insertSelective(UserInfo record);

    @Select({
        "select",
        "id, name, surname, description, email, phone_num, locale, active, deleted, login_id, ",
        "login_pass, creation_time, last_updated_time, last_login_time",
        "from user_info",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="surname", property="surname", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone_num", property="phoneNum", jdbcType=JdbcType.VARCHAR),
        @Result(column="locale", property="locale", jdbcType=JdbcType.VARCHAR),
        @Result(column="active", property="active", jdbcType=JdbcType.INTEGER),
        @Result(column="deleted", property="deleted", jdbcType=JdbcType.INTEGER),
        @Result(column="login_id", property="loginId", jdbcType=JdbcType.VARCHAR),
        @Result(column="login_pass", property="loginPass", jdbcType=JdbcType.VARCHAR),
        @Result(column="creation_time", property="creationTime", jdbcType=JdbcType.DATE),
        @Result(column="last_updated_time", property="lastUpdatedTime", jdbcType=JdbcType.DATE),
        @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.DATE)
    })
    UserInfo selectByPrimaryKey(long id);

    @UpdateProvider(type=UserInfoSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UserInfo record);

    @Update({
        "update user_info",
        "set name = #{name,jdbcType=VARCHAR},",
          "surname = #{surname,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "phone_num = #{phoneNum,jdbcType=VARCHAR},",
          "locale = #{locale,jdbcType=VARCHAR},",
          "active = #{active,jdbcType=INTEGER},",
          "deleted = #{deleted,jdbcType=INTEGER},",
          "login_id = #{loginId,jdbcType=VARCHAR},",
          "login_pass = #{loginPass,jdbcType=VARCHAR},",
          "creation_time = #{creationTime,jdbcType=DATE},",
          "last_updated_time = #{lastUpdatedTime,jdbcType=DATE},",
          "last_login_time = #{lastLoginTime,jdbcType=DATE}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(UserInfo record);
}